<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head th:include="include :: header">
</head>
<link rel="stylesheet" th:href="@{/css/yw.css}">

<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        项目联络单回复
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 项目编号 </label>
                                    <input type="text" name="proCode" class="form-control">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 项目名称</label>
                                    <input type="text" name="proName" class="form-control">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 需方</label>
                                    <input type="text" name="customer" class="form-control">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 地点</label>
                                    <input type="text" name="insSite" class="form-control">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 发起人</label>
                                    <input type="text" name="editName1" class="form-control">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 参与人</label>
                                    <input type="text" name="participants" class="form-control">
                                </div>
                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 发起日期</label>
                                    <input type="text" class="form-control datepicker" name="beginTime"
                                           placeholder="开始日期" readonly>
                                    至
                                    <input type="text" class="form-control datepicker" name="endTime"
                                           placeholder="结束日期" readonly>
                                </div>

                                <div class="form-group" style="margin-right: 10px;">
                                    <label> 状态</label>
                                    <select type="value" class="form-control" autocomplete="off" name="detailStatus2">
                                        <option value="" style="text-align: center" selected>请选择</option>
                                        <option value="1" style="text-align: center">未提交</option>
                                        <option value="2" style="text-align: center">待审核</option>
                                        <!--<option value="3" style="text-align: center">审核通过</option>-->
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        style="margin-top: 5px;">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table class="table table-bordered" id="table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer">
</div>
<script th:inline="javascript">
    var table;
    /**
     * 表格搜索
     */
    $("#btn-search").click(function () {
        js.table.search(table);
    });


    $(function () {
        table = js.table.init({
            id: "table",
            url: ctx + "queryContactList",
            showColumns: false,
            pageSize: 300,
            pagination: true,
            columns: [
                {
                    title: '序号', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    title: "主表主键", field: 'id'
                    , visible: false
                },
                {
                    title: "子表主键", field: 'detailId'
                    , visible: false
                },
                {
                    title: "编辑身份", field: 'conIdentity'
                    , visible: false
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName'},
                {title: "联络类型", field: 'conType'},
                {title: "需方", field: 'customer'},
                {title: "安装地点", field: 'insSite'},
                {title: "数量", field: 'proNum'},
                {title: "发起部门", field: 'branchName'},
                {
                    title: "参与部门", field: 'participants',width:'150px',
                    formatter: function (value, row, index) {
                        return changeRow(value)
                    }
                },
                {
                    title: "发起时间", field: 'createTime',
                    formatter:
                        function (value, row, index) {
                            return changeDateFormat(value)
                        }
                },
                {
                    title: "审核意见", field: 'examineOpin',
                    formatter:
                        function (value) {
                            if (value === "" || value === null || value === undefined) {
                                return "";
                            } else {
                                return value;
                            }
                        }
                },
                {
                    title: "状态", field: 'detailStatus2',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return "未提交";
                        } else if (value === 2) {
                            return "待审核";
                        } else if (value === 3) {
                            return "审核通过";
                        }
                    }
                },
                {
                    title: "操作", width:'120px',formatter:
                        function (value, row, index) {
                            var actions = [];
                            if (row.detailStatus2 === 1) {
                                if (row.editId2===0||row.editId2===null){
                                    if (hasP('lia:reply:edit')) {
                                        actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'contact/contactInfoEdit?detailId=' + row.detailId + '" > 编辑</a> ');
                                    }
                                    if (hasP('lia:reply:submit')) {
                                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="submitContact(' + row.detailId + ')" > 提交</a> ');
                                    }
                                } else if ( row.editId2 === sessionUser.id) {
                                    if (hasP('lia:reply:edit')) {
                                        actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'contact/contactInfoEdit?detailId=' + row.detailId + '" > 编辑</a> ');
                                    }
                                    if (hasP('lia:reply:submit')) {
                                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="submitContact(' + row.detailId + ')" > 提交</a> ');
                                    }
                                }

                            }
                            if (hasP('lia:reply:del')) {
                                if (row.conIdentity === 1 && row.detailStatus2 === 1) {
                                    actions.push('<a class="btn btn-danger btn-xs"  href="javascript:void(0)" onclick="delContact(' + row.id + ')"> 删除</a> ');
                                }
                            }
                            actions.push('<a class="btn btn-info btn-xs" href="' + ctx + 'contact/contactReturnSelect?detailId=' + row.detailId + '" > 查看</a> ');
                            return actions.join('');
                        }
                }
            ]
        })
        ;

    });

    /** 删除联络单*/
    function delContact(id) {
        js.modal.confirm("确认删除吗？", function (result) {
            if (result) {
                callBack();
            }
            $.ajax({
                type: 'POST',
                url: ctx + "contact/delContact",
                data: {'id': id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        $("#table").bootstrapTable('refresh');
                        js.modal.closeLoading();
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
    }

    /**
     * 日期格式转换
     * @param value
     * @returns {*}
     */
    function changeDateFormat(value) {
        if (value == '' || value == undefined) {
            return "";
        }
        var myDate = new Date(value);
        //获取当前年
        var year = myDate.getFullYear();
        //获取当前月
        var month = myDate.getMonth() + 1;
        month = month < 10 ? "0" + month : month;
        //获取当前日
        var date = myDate.getDate();
        date = date < 10 ? "0" + date : date;
        var h = myDate.getHours();       //获取当前小时数(0-23)
        h = h < 10 ? "0" + h : h;
        var m = myDate.getMinutes();     //获取当前分钟数(0-59)
        m = m < 10 ? "0" + m : m;
        var s = myDate.getSeconds();
        s = s < 10 ? "0" + s : s;
        var time = year + '-' + month + "-" + date;
        return time;
    }

    function changeRow(value) {
        if (value === null) {
            return "";
        }
        var code = value;
        var code2 = code.replace(/,/g, "<br>");
        return code2.replace(/，/g, "<br>");
    }

    function submitContact(detailId) {
        js.modal.confirm("确认提交吗？", function (result) {
            if (result) {
                callBack();
            }
            js.post({
                url: ctx + "contact/submit",
                data: {'detailId': detailId},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        $("#table").bootstrapTable('refresh');
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        })
    }

</script>